package com.scommunity.admin.controller;

import com.github.pagehelper.PageInfo;
import com.scommunity.admin.vo.UserQO;
import com.scommunity.common.ResponseResult;
import com.scommunity.domain.User;
import com.scommunity.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    IUserService userService;

    @GetMapping({"/list/{pageNum}"})
    public Object list(UserQO userQO, @PathVariable(required = false) Integer pageNum) {
        if (pageNum == null) {
            pageNum = 1;
        }
        PageInfo<User> pageInfo = userService.findPageInfoByCondition(userQO, pageNum, 5);
        return ResponseResult.success(pageInfo);
    }

    @GetMapping("/getAll")
    public Object getAll() {
        List<User> users = userService.getAll();
        return ResponseResult.success(users);
    }

    @PostMapping("/update")
    public Object update(@RequestBody User user) {
        userService.update(user);
        return ResponseResult.success();
    }

}
